package com.ruoyi.payLog.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.WxPaymentConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.payLog.domain.PayLogs;
import com.ruoyi.payLog.service.IPayLogsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 支付记录信息Controller
 * 
 * @author ruoyi
 * @date 2025-06-16
 */
@Api("支付日志信息管理")
@RestController
@RequestMapping("/ruoyi/payLogs")
public class PayLogsController extends BaseController
{
    @Autowired
    private IPayLogsService payLogsService;

    @Resource
    private WxPaymentConfig wxPaymentConfig;

    /**
     * 获取微信支付配置信息
     */
    @ApiOperation("测试接口")
    @GetMapping
    public AjaxResult getWxPaymentConfig()
    {
        String mchId = wxPaymentConfig.getMchId();
        return success(mchId);
    }

    /**
     * 查询支付记录信息列表
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:payLogs:list')")
    @GetMapping("/list")
    public TableDataInfo list(PayLogs payLogs)
    {
        startPage();
        List<PayLogs> list = payLogsService.selectPayLogsList(payLogs);
        return getDataTable(list);
    }

    /**
     * 导出支付记录信息列表
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:payLogs:export')")
    @Log(title = "支付记录信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PayLogs payLogs)
    {
        List<PayLogs> list = payLogsService.selectPayLogsList(payLogs);
        ExcelUtil<PayLogs> util = new ExcelUtil<PayLogs>(PayLogs.class);
        util.exportExcel(response, list, "支付记录信息数据");
    }

    /**
     * 获取支付记录信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:payLogs:query')")
    @GetMapping(value = "/{paymentId}")
    public AjaxResult getInfo(@PathVariable("paymentId") Long paymentId)
    {
        return success(payLogsService.selectPayLogsByPaymentId(paymentId));
    }

    /**
     * 根据订单id获取支付记录信息
     */
    @GetMapping("/getPayLogsByOrderId/{orderId}")
    public AjaxResult getPayLogsByOrderId(@PathVariable("orderId") Long orderId)
    {
        return success(payLogsService.selectPayLogsByOrderId(orderId));
    }

    /**
     * 根据商品订单id获取支付记录信息
     */
    @GetMapping("/getPayLogsByGoodsOrderId/{orderId}")
    public AjaxResult getPayLogsByGoodsOrderId(@PathVariable("orderId") Long orderId)
    {
        return success(payLogsService.getPayLogsByGoodsOrderId(orderId));
    }

    /**
     * 新增支付记录信息
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:payLogs:add')")
    @Log(title = "支付记录信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PayLogs payLogs)
    {
        return toAjax(payLogsService.insertPayLogs(payLogs));
    }

    /**
     * 修改支付记录信息
     */
//    @PreAuthorize("@ss.hasPermi('ruoyi:payLogs:edit')")
    @Log(title = "支付记录信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PayLogs payLogs)
    {
        return toAjax(payLogsService.updatePayLogs(payLogs));
    }

    /**
     * 删除支付记录信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi:payLogs:remove')")
    @Log(title = "支付记录信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paymentIds}")
    public AjaxResult remove(@PathVariable Long[] paymentIds)
    {
        return toAjax(payLogsService.deletePayLogsByPaymentIds(paymentIds));
    }
}
